package com.shangcheng.dubbo.api;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shangcheng.dubbo.mappers.PmsProductAttributeValueMapper;
import com.shangcheng.model.domain.CmsPrefrenceAreaProductRelation;
import com.shangcheng.model.domain.PmsMemberPrice;
import com.shangcheng.model.domain.PmsProductAttributeValue;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeValueApiImpl implements PmsProductAttributeValueApi {
    @Autowired
    private PmsProductAttributeValueMapper productAttributeValueMapper;

    @Override
    public void save(List<PmsProductAttributeValue> productAttributeValueList, Long id) {
        if (ObjectUtil.isNotEmpty(productAttributeValueList)) {
            for (PmsProductAttributeValue pmsProductAttributeValue : productAttributeValueList) {
                pmsProductAttributeValue.setProductId(id);
                productAttributeValueMapper.insert(pmsProductAttributeValue);
            }
        }
    }

    @Override
    public List<PmsProductAttributeValue> findByProductId(Integer id) {
        return productAttributeValueMapper.selectList(new LambdaQueryWrapper<PmsProductAttributeValue>().eq(PmsProductAttributeValue::getProductId, id));
    }

    @Override
    public void updateById(Integer id, List<PmsProductAttributeValue> productAttributeValueList) {
        productAttributeValueMapper.delete(new LambdaQueryWrapper<PmsProductAttributeValue>().eq(PmsProductAttributeValue::getProductId, id));
        this.save(productAttributeValueList, Convert.toLong(id));
    }
}
